package MyScanner;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

//Token块，记录对应源代码扫描后的属性字流，以及源代码路径，输出路径
public class TokensBlock {
    private final String srcPath;
    private String outPath;
    private final List<Token> tokenList;

    public TokensBlock(String srcPath)
    {
        this.srcPath = srcPath;
        tokenList = new ArrayList<>();
    }
    public TokensBlock(String srcPath, String outPath)
    {
        this.srcPath = srcPath;
        this.outPath = outPath;
        tokenList = new ArrayList<>();
    }

    public void addToken(Token token)
    {
        tokenList.add(token);

    }
    public void addToken(Collection<Token> tokens)
    {
        tokenList.addAll(tokens);
    }

    public void setOutPath(String outPath) {
        this.outPath = outPath;
    }
    public int getTokensSize()
    {
        return tokenList.size();
    }

    public Token[] getTokens()
    {
        Token[] array = new Token[tokenList.size()];
        int i = 0;
        for (Token token: tokenList)
            array[i++] = token;
        return array;
    }
}
